﻿using Sql_Dataprovider;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace DACK_N28_QLRCP
{
    public class Phim
    {

        private int _MaPhim;
        public int MaPhim
        {
            get { return _MaPhim; }
            set { _MaPhim = value; }
        }


        private string _TenPhim;
        public string TenPhim
        {
            get { return _TenPhim; }
            set { _TenPhim = value; }
        }


        private string _NuocSanXuat;
        public string NuocSanXuat
        {
            get { return _NuocSanXuat; }
            set { _NuocSanXuat = value; }
        }


        private string _HangPhim;
        public string HangPhim
        {
            get { return _HangPhim; }
            set { _HangPhim = value; }
        }


        private string _GioiThieuPhim;
        public string GioiThieuPhim
        {
            get { return _GioiThieuPhim; }
            set { _GioiThieuPhim = value; }
        }


        private string _Trailer;
        public string Trailer
        {
            get { return _Trailer; }
            set { _Trailer = value; }
        }


        private string _Poster;
        public string Poster
        {
            get { return _Poster; }
            set { _Poster = value; }
        }


        private int _MaDinhDang;
        public int MaDinhDang
        {
            get { return _MaDinhDang; }
            set { _MaDinhDang = value; }
        }
        private int _ThoiLuong;

        public int ThoiLuong
        {
            get { return _ThoiLuong; }
            set { _ThoiLuong = value; }
        }

    }

    public class Phim_DAO
    {
        public static Boolean Them_Phim(Phim NEWS)
        {
            Sql_DataProvider INS = new Sql_DataProvider();
            string sql = string.Format("Them_Phim");
            SqlParameter[] pr = {
                                    new SqlParameter("@TenPhim",NEWS.TenPhim),
                                    new SqlParameter("@NuocSanXuat",NEWS.NuocSanXuat),
                                    new SqlParameter("@HangPhim",NEWS.HangPhim),
                                    new SqlParameter("@GioiThieu", NEWS.GioiThieuPhim),
                                    new SqlParameter("@Trailer", NEWS.Trailer),
                                    new SqlParameter("@Poster",NEWS.Poster),
                                    new SqlParameter("@MaDinhDang",NEWS.MaDinhDang),
                                    new SqlParameter("@ThoiLuong",NEWS.ThoiLuong)};

            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }

            return INS.SQL_ExecuteNonQuery(cmd);

        }

        public static Boolean Xoa_Phim(int MaPhim)
        { 
            Sql_DataProvider DELS = new Sql_DataProvider();
            string sql = string.Format("Xoa_Phim");
                SqlParameter pr = new SqlParameter("@MaPhim",MaPhim);
                SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(pr);
            return DELS.SQL_ExecuteNonQuery(cmd);
        }

        public static Boolean CapNhatPhim(Phim CapNhat)
        {
            
            string sql = string.Format("CapNhat_Phim");
            SqlParameter[] pr = {
                                    new SqlParameter("@MaPhim",CapNhat.MaPhim),
                                    new SqlParameter("@TenPhim",CapNhat.TenPhim),
                                    new SqlParameter("@NuocSanXuat",CapNhat.NuocSanXuat),
                                    new SqlParameter("@HangPhim",CapNhat.HangPhim),
                                    new SqlParameter("@GioiThieuPhim", CapNhat.GioiThieuPhim),
                                    new SqlParameter("@Trailer", CapNhat.Trailer),
                                    new SqlParameter("@Poster",CapNhat.Poster),
                                    new SqlParameter("@MaDinhDang",CapNhat.MaDinhDang)};
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            for (int i = 0; i < pr.Count(); i++)
            {
                cmd.Parameters.Add(pr[i]);
            }
            
            Sql_DataProvider INS = new Sql_DataProvider();
            return INS.SQL_ExecuteNonQuery(cmd);
        }

        public static Phim Get_Phim(int MaPhim)
    {
            Phim GETS = new Phim();
            Sql_DataProvider Getp = new Sql_DataProvider();
            SqlDataReader reader = Getp.SQL_ExcuteQueryReader(string.Format("select * from Phim where MaPhim = {0}", MaPhim));
            if (reader.HasRows)
            {
                reader.Read();
                GETS.MaPhim = Convert.ToInt32(reader["MaPhim"]);
                GETS.TenPhim = reader["TenPhim"].ToString();
                GETS.GioiThieuPhim = reader["GioiThieuPhim"].ToString();
                GETS.HangPhim = reader["HangPhim"].ToString();
                GETS.NuocSanXuat = reader["HangPhim"].ToString();
                GETS.MaDinhDang = Convert.ToInt32(reader["MaDinhDang"]);
                GETS.Poster = reader["Poster"].ToString();
                GETS.Trailer = reader["Trailer"].ToString();
            }
            Getp.Connect.Close();
            return GETS;
    }
    }
}
